package com.neusoft.neu24.mybatis01;

import com.neusoft.neu24.mybatis01.entity.Admins;
import com.neusoft.neu24.mybatis01.mapper.AdminsMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MainApp {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        SqlSession session = sqlSessionFactory.openSession();
        AdminsMapper  mapper =  session.getMapper(AdminsMapper.class);

         List<Admins> las =  mapper.selectAll();
         las.forEach( System.out::println );


    }

    public static void main1(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        // 创建SqlSession  ---- 》  Connection
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            // 执行SQL语句
            List<Admins> las  =  sqlSession.selectList("com.neusoft.neu24.mybatis01.entity.Admins.selectBlog");
            las.forEach( System.out::println );
        }
        catch (Exception ex ){
        }
        sqlSession.close();
    }
}
